package com.itheima.bos.web.action.base;

import java.util.Date;
import java.util.List;

import org.apache.struts2.convention.annotation.Action;
import org.apache.struts2.convention.annotation.Result;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.PageRequest;
import org.springframework.data.domain.Pageable;

import com.itheima.bos.domain.base.TakeTime;
import com.itheima.bos.service.base.ITakeTimeSerivce;
import com.itheima.bos.web.action.common.BaseAction;
import com.opensymphony.xwork2.ActionContext;

public class TakeTimeAction extends BaseAction<TakeTime> {

	// 注入serivce
	@Autowired
	private ITakeTimeSerivce takeTimeService;

	// 添加收派时间
	@Action(value = "takeTime_save", results = { @Result(name = "success", location = "/pages/base/take_time.html", type = "redirect") })
	public String save() {

		// 给收派时间管理表添加当前系统时间为操作时间
		model.setOperatingTime(new Date());
		
		//调用业务层添加收派时间
		takeTimeService.sava(model);
		
		return SUCCESS;
	}
	
	//分页查询收派时间
	@Action(value="takeTime_pageQurey",results={@Result(name="success",type="json")})
	public String pageQurey(){
		//封装分页查询条件
		Pageable pageable = new PageRequest(page-1,rows);
		//调用业务层，进行查询
		Page<TakeTime>pageData=takeTimeService.findPageData(pageable);
		//压进栈顶
		pushPageDataToValueStack(pageData);
		return SUCCESS;
	}
	
	//查询所有收派时间
	@Action(value="takeTime_findAll",results={@Result(name="success",type="json")})
	public String findAll(){
		//调用业务层查询所有的收派时间
		List<TakeTime>takeTimes=takeTimeService.findAll();
		pushPageDataToValueStack(takeTimes);
		return SUCCESS;
	}
}
